<?php

/**
 *Simple CRUD Code Generator
 *Email:  support@crazedcoders.com
 *Website: http://www.crazedcoders.com/
 *Copyright (C) 2007 CrazedCoders
 *
 *This program is free software: you can redistribute it and/or modify
 *it under the terms of the GNU General Public License as published by
 *the Free Software Foundation, either version 3 of the License, or
 *(at your option) any later version.
 *
 *THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 *SOFTWARE.
 *
 *You should have received a copy of the GNU General Public License
 *along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * generates a Services.mxml file for flex
 * pre: $tables is already populated with key information
 */
function generateServicesMxml( $tables ) {
	$relativeFlexPath = con::$relativeFlexPath;
	$businessPath = "$relativeFlexPath/business";
	$filePath = "$businessPath/Services.mxml";
	$includePath = "$businessPath/Services.include";
	$export =
'<?xml version="1.0" encoding="utf-8"?>
<!--

 Simple CRUD Code Generator
 Email:  support@crazedcoders.com
 Website: http://www.crazedcoders.com/
 Copyright (C) 2007 CrazedCoders

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

-->
<cairngorm:ServiceLocator
	xmlns:mx="http://www.adobe.com/2006/mxml"
	xmlns:cairngorm="com.adobe.cairngorm.business.*">

	<!-- add a service for each object -->

';

	foreach( $tables as $tablename=>$columns ) {
		$export .=
'
	<mx:RemoteObject id="'.toCamelCase( $tablename ).'DaoRo"
		destination="'.toCamelCase( $tablename ).'Dao"
		source="'.con::$package.'.'.toCamelCase( $tablename ).'Dao"
		showBusyCursor="true" />

';

	}

#	<mx:RemoteObject id="RolesDaoRO"
#		destination="RolesDao"
#		source="com.crazedcoders.loginscreen.RolesDao"
#		fault="event.token.faultHandler(event)"
#		result="event.token.resultHandler(event)"
#		showBusyCursor="true" />
#
#	<mx:RemoteObject id="ForumDAO"
#		destination="ForumDAO"
#		source="com.crazedcoders.loginscreen.ForumDAO"
#		fault="event.token.faultHandler(event)"
#		result="event.token.resultHandler(event)"
#		showBusyCursor="true" />

	$export .=
'
	<!-- user included code coming up -->
';
	$include = "";
	if( file_exists( $includePath ) ) {
		$fh = fopen( $includePath, "r" );
		if( $fh ) {
			while( ! feof( $fh ) ) {
				$include .= fread( $fh, 8192 );
			}
			fclose( $fh );
		}
	}
	else {
		$include .=
'	<!-- no custom code .include found in '.$includePath.' -->
';
	}
	$export .= $include;

	$export .=
'
	<!-- end user included code -->

</cairngorm:ServiceLocator>';
	return( $export );
}


?>
